<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    <%@ include file="/WEB-INF/component/commonTagLib.jsp" %> 
<!DOCTYPE html>
<html>
<head>
	<title>成功校验药品预览</title>
	<%@ include file="/WEB-INF/component/commonCSS.jsp"%>
    <!--[if lt IE 9]>
        <script src="lib/js/html5shiv.min.js"></script>
        <script src="lib/js/respond.min.js"></script>
    <![endif]-->
    <style type="text/css">
    .box-body{
    margin-top:-2px;
    }    	
    </style>
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
    <section class="content-header">
        <h1>成功校验药品</h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
            <li class="active"><a href="#">目录管理</a></li>
            <li class="active"><a href="#">药品导入查看</a></li>
        </ol>
    </section>
    
    <section class="content">
      <form id="form" method="post" class="form-horizontal">    
        <div class=" box box-success">
            <div class="box-body">
               <div class="input">
                    <div class="textalign">通用名：</div>
                    <div class="boxinput">
                        <input type="text" class="textinput" id="drugName" name="drugName" placeholder="通用名" />
                    </div>
                    <div class="textalign1">生产企业：</div>
                    <div class="boxinput">
                        <input type="text" class="textinput" id="compName" name="compName" placeholder="生产企业" />
                    </div>
                    <div class="textalign" >
                       <button     id="selectSerch"   type="button"  onclick="gridSerch()"  class="btn btn-success btn-sm">查&nbsp;询</button>
                    </div>
               </div>
               
            </div>
           </div>
        </form> 
        <table class="jqgrid" id="list4"></table>
        <div id="prowed2"></div>
		<div class=" box box-warning bottongroup" id="bottongroup">
			<label id="ipd" onclick="importGoods('0');" class="btn btn-default btn-sm">导&nbsp;入</label>
			<label id="deld"  onclick="deleteGoods('1');"   class="btn btn-default btn-sm" >放&nbsp;弃</label>
			<label  onclick="window.location.href='${ctx}/bidProject/toImportFileList.html?projId=${projId}';"   class="btn btn-default btn-sm" >返&nbsp;回</label>
		</div>              
                        <div class="form-group form-group-xs">
                                <table class="jqgrid col-sm-1" id="gridlist1"></table>
        <div id="gridpage1 col-sm-1"></div>
                            </div>
                      
         
            
            
            
            
           
	<table class="jqgrid" id="list4"></table>
<div style="margin-top: 10px;"></div>
	<form action="${ctx}/stdCompinfo/toStdCompinfoDetailJsp.html"
		id="FormDetail" method="post">
		<input type="hidden" name="compCodeDetail" id="compCodeDetail" /> 
	</form>
</section>
<%@ include file="/WEB-INF/component/commonJS.jsp"%>
<script type="text/javascript">
		function importGoods(){
			$.post("${pageContext.request.contextPath}/bidProject/checkReImport.html", {
				fileId : '${fileId}'
			}, function(result) {
				if (result.msg != "") {
					$.HN.message.confirm(result.msg, '', '').on(function (e) {
			              if (e) {
			            	  importData();
			              }
			          });
				} else {
					importData();
				}
			}, "json")
		}
		
		function importData(){
			$.post("${pageContext.request.contextPath}/bidProject/importDrug.html", {
				fileId : '${fileId}'
			}, function(result) {
				if (result.success) {
					gridSerch();
					$.HN.message.alert(result.msg, "消息", "success");
					$("#ipd").hide(); 
					$("#deld").hide(); 
					window.location.href='${ctx}/bidProject/toImportFileList.html?projId=${projId}';
				} else {
					$.HN.message.alert(result.msg, "消息", "error");
				}
			}, "json")
		}
		function deleteGoods(){
			 $.HN.message.confirm("确定要放弃吗？", '', '').on(function (e) {
	              if (e) {
	            	  $.post("${pageContext.request.contextPath}/bidProject/deleteImportDrug.html", {
	      				fileId : '${fileId}'
	      			}, function(result) {
	      				if (result.success) {
	      					gridSerch();
	      					$.HN.message.alert("放弃成功！", "消息", "success");
	      					$("#ipd").hide(); 
	    					$("#deld").hide();
	    					window.location.href='${ctx}/bidProject/toImportFileList.html?projId=${projId}';
	      				} else {
	      					$.HN.message.alert(result.msg, "消息", "error");
	      				}
	      			}, "json")
	                  
	              }
	          });
			
			
		}
		
		function switchStatus(goodsCode,status){
			var msg = "停用";
			if(status == 1){
				var msg = "启用";
			}
			$.HN.message.confirm("确定"+msg+"吗？", '', '').on(function (e) {
	            if (e) {
			$.post("${pageContext.request.contextPath}/baseGoods/switchStatus.html", {
				goodsCode : goodsCode, status : status
			}, function(result) {
				if (result.success) {
					gridSerch();
					$.HN.message.alert("操作成功！", "消息", "success");
				} else {
					$.HN.message.alert("操作失败！", "消息", "error");
				}
			}, "json")
	            }
			}); 
		}
		
		function batchSwitchStatus(status){
			var msg = "停用";
			if(status == 1){
				var msg = "启用";
			}
			var rowIds = $("#list4").jqGrid("getGridParam", "selarrrow") || [];
			if (rowIds.length <= 0) {
				$.HN.message.alert("请选择要操作的行！", "消息", "error");
				return;
			}
			$.HN.message.confirm("确定"+msg+"吗？", '', '').on(function (e) {
	            if (e) {
			var list = [];
			for (var i=0; i<rowIds.length; i++) {
				rowId = rowIds[i];
				var rowdata = $("#list4").jqGrid('getRowData', rowIds[i]);
				list.push({"goodsCode":rowId,
		    		"status":status});
			}
			$.post("${pageContext.request.contextPath}/baseGoods/batchSwitchStatus.html", {
				"array" : json.jsonToString(list)
			}, function(result) {
				if (result.success) {
					gridSerch();
					$.HN.message.alert("操作成功！", "消息", "success");
				} else {
					$.HN.message.alert("操作失败！", "消息", "error");
				}
			}, "json")
	            }
			});
		}
		
		$(function () {
			
			 //加载页面光标在名字框内，位于第一个
			   $("#drugName").focus();
			   
			 //绑定回车     id="selectSerch"   
			   $('#drugName,#compName').bind('keydown', function(event) {
			       if (event.keyCode == "13") {        //13 位电脑上回车键的位置代码
			           $('#selectSerch').click();
			       }
			   }); 
			    
			
		jQuery("#list4").jqGrid({
			url: "${ctx}/bidProject/getImportDrugView.html?fileId=${fileId}&projId=${projId}",
		    mtype: "POST",
			datatype: "json",
			autowidth: true,
			shrinkToFit:true,
			height: 270,
		   	colNames:[
		   	          '药品编码',
		   	          '通用名',
		   	          '剂型',
		   	          '规格',
		   	          '转换系数',
		   	          '单位',
		   	          '材质',
		   	          '生产企业'
		   	          ],
		   	colModel:[
				{name:'drugCode',index:'drugCode', width:100, align:"center",sorttype:false},
		   		{name:'drugName',index:'drugName', width:140,align:"left", sorttype:false,
					 formatter:function(val, opts, row) {
						  return "<a href=\"javascript:void(0);\" onclick=\"showDrugInfo('"+row.drugCode+"', '"+val+"')\">"+val+"</a>"
						 }},
		   		{name:'formName',index:'formName', width:80, align:"center"},
		   		{name:'specName',index:'specName', width:80, align:"left",sorttype:false},
		   		{name:'factor',index:'factor', width:80, align:"center",sorttype:false},
		   		{name:'unitName',index:'unitName', width:40, align:"center",sorttype:false},
		   		{name:'materialName',index:'materialName', width:80, align:"left",sorttype:false},
		   		{name:'compName',index:'compName', width:180, align:"left",sorttype:false,
		   			formatter:function(val, opts,row) {
			   			 return "<a href=\"javascript:void(0);\" onclick=\"showCompInfo('"+row.compCode+"', '"+ val +"')\">"+val+"</a>"
			   			}
		  		}
		   		
		   	],
			 rowNum: 0,
		     //rowList: [10, 20, 50, 100],
		     rownumbers: true,
		     multiselect: false,
		     //pager: "#prowed2",
		     viewrecords: true,
		     caption: "药品列表",
		   //序号宽度自动变化
             gridComplete:function(){
                 //序号列宽度自适应（参数为jqgridID）
                 autoRNWidth("list4");
                 //数据只有一条时默认选中（参数为jqgridID）
                 selectByOneData("list4");
             },
		     editurl:"proPlanItemListHis.jsp",
		     jsonReader: {
		         repeatitems: false,
		         id: "goodsCode"
		     }
		   	
		});
			 
			jQuery("#list4").jqGrid('navGrid',"prowed2",{edit:false,add:false,del:false});
			$(window).trigger("resize");
			
			$("#drugCat").HNSelect({
		        url: "${pageContext.request.contextPath}/selectController/getDicSys.html", data: { ID: '115' },defaultselect:'${form.patternType}',  defaultText: "<option value=''>请选择</option>",
		    });
		});
		
		function gridSerch() {
			var drugName = $.trim($("#drugName").val());
			var compName = $.trim($("#compName").val());
			$("#list4").jqGrid('setGridParam',{  
		        datatype:'json',
		        postData:{
		        		"drugName":drugName,
		        		"compName":compName},
		        		page:1
		    }).trigger("reloadGrid"); //重新载入  
		}
		
		    
		    function stop(){
		    	var checked = false;
		    	 $("input.cbox").each(function() {
		    	     if($(this).is(":checked")) {
		    	    	 checked = true;
		    	    	 return false;
		    	     };
		    	 });
		    	 
		    	 if (!checked) {
		    		 $.HN.message.alert('请选择要停用的条目', '提示信息', 'failed');
		    	 }else{
		   	 $.HN.message.confirm("确定要停用吗？", '', '').on(function (e) {
		           if (e) {
		               $.HN.message.alert('操作成功！', '提示信息', 'success');
		               window.location.href="onSellDrugListCenter.jsp";
		               
		           }
		       });
			   
		       }
		    }
		   $("#allDelete1").click(function(){
			   var checked = false;
		   	 $("input.cbox").each(function() {
		   	     if($(this).is(":checked")) {
		   	    	 checked = true;
		   	    	 return false;
		   	     };
		   	 });
		   	 
		   	 if (!checked) {
		   		 $.HN.message.alert('请选择要启用的条目', '提示信息', 'failed');
		   	 }else{
		     	 $.HN.message.confirm("确定要启用吗", '', '').on(function (e) {
		              if (e) {
		                  $.HN.message.alert('操作成功！', '提示信息', 'success');
		                  window.location.href="onSellDrugListCenter.jsp";
		                  
		              }
		          });
		   	 }
		     });
		   
			function goJsp(n1){
				
				var opt ={
						url:"../../jsp/price/priceChangeExeDetailGrid.jsp",
						title:"newwindow",
		style:{height:400,width:890,top:200,left:270}
				};
				$.HN.dialog.open(opt);
				
		}    
		    function selectComp(){
		 	   
		 		$("#compCode").val("");
		 	    $("#compName").val("");
		 	 gridCompSerch();
		 	   $('#selectComp').modal({
		 			keyboard : true
		 		});
		 	   
		 	  // window.open("${pageContext.request.contextPath}/stdDrug/toSelectComp.html?value=prodPompId&text=comp","newwin","dialogHeight: 200px; dialogWidth: 150px; dialogTop: 458px; dialogLeft: 166px; edge: Raised; center: Yes; help: Yes; resizable: Yes; status: Yes;");
		    }
		    function gridCompSerch() {
		    	var compCode = $("#compCode").val();
		    	var compName = $("#compName").val();
		 		$("#gridlist1").jqGrid('setGridParam',{  
		 	        datatype:'json',
		 	        postData:{"compCode":compCode,
		 	        		"compName":compName}
		 	    }).trigger("reloadGrid"); //重新载入  
		 	}
		    function gridOk(){
		 	   var compId = $("#gridlist1").jqGrid('getGridParam', 'selrow');
		        if (compId == null) {
		     	   $.HN.message.alert('请至少选一行！', '提示信息', 'error');
		            return;
		        }
		        var rowdata = $("#gridlist1").jqGrid('getRowData', compId);
		        $("#prodPompId").val(compId);
		        $("#comp").val(rowdata.compName);
		        $("#selectComp").modal("hide");
		        
		    }
		    function cleandata(){
		 	   $("#prodPompId").val("");
		        $("#comp").val("");
		        $("#selectComp").modal("hide");
		    }
		    function operResult(val){
		        
		    }
		    function fileUp(){
		    	$('#batchImport').modal({
                    keyboard: true
                });
		    }
		    
		    
		    
		    $('#importform').ajaxForm({ 
			    dataType: 'json', 
			    
		    	success: function(returnData) {
		    	if(returnData.success) {
		    		$.HN.message.alert('导入成功！', '提示信息', 'success');
		    		$("#importform").modal("hide");
				}else{
					$.HN.message.alert('添加失败，请重新添加！', '提示信息', 'success');
		    	}
		       } 	
		   });
</script>
</body>
</html>